package com.itwang.test7;

public class GirlFriendTest {
    public static void main(String[] args) {
        // 1.定义数组存入女朋友的对象
        GirlFriend [] arr = new GirlFriend[4];

        // 2.创建女朋友对象
        GirlFriend gf1 = new GirlFriend("范冰冰",18,"美若天仙","做饭");
        GirlFriend gf2 = new GirlFriend("古力娜扎",19,"沉鱼落雁","吃美食");
        GirlFriend gf3 = new GirlFriend("小惠惠",20,"萌妹子","看书，学习");
        GirlFriend gf4 = new GirlFriend("小莉莉",21,"憨妹子","睡觉");

        //3.把对象添加到数组当中
        arr[0] = gf1;
        arr[1] = gf2;
        arr[2] = gf3;
        arr[3] = gf4;

        //4.求和
        int sum= 0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriend gf = arr[i];
            sum += gf.getAge();
        }

        //5.求平均值
        double avg = sum * 1.0 / arr.length;
        System.out.println(avg);

        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriend gf = arr[i];
            if(gf.getAge() < avg) {
                count++;
                System.out.println(gf.getName() + gf.getAge() + gf.getGender() + gf.getHobby());
            }
        }
        System.out.println("年龄比平均值低的女朋友有" + count + "个");
    }
}
